<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2017/1/6
 * Time: 9:45
 */

require '../vendor/autoload.php';

$client = new Elasticsearch\Client();

//Index a document
$params = array();
$params['body']  = array('testField' => 'abc');
$params['index'] = 'my_index';
$params['type']  = 'my_type';
$params['id']    = 'my_id';
//$ret = $client->index($params);
//var_dump($ret);

//Get a document
$getParams = array();
$getParams['index'] = 'my_index';
$getParams['type']  = 'my_type';
$getParams['id']    = 'my_id';
$retDoc = $client->get($getParams);
//var_dump($retDoc);

//Search for a document

$searchParams['index'] = 'my_index';
$searchParams['type']  = 'my_type';
$searchParams['body']['query']['match']['testField'] = 'abc';
$retDoc = $client->search($searchParams);
//var_dump($retDoc);

//Delete a document

$deleteParams = array();
$deleteParams['index'] = 'my_index';
$deleteParams['type'] = 'my_type';
$deleteParams['id'] = 'my_id';
//$retDelete = $client->delete($deleteParams);

//Delete an index

$deleteParams = array();
$deleteParams['index'] = 'my_index';
$client->indices()->delete($deleteParams);

//Create an index

$indexParams['index'] = 'my_index';
$indexParams['body']['settings']['number_of_shards'] = 2;
$indexParams['body']['settings']['number_of_replicas'] = 0;
$client->indices()->create($indexParams);